<template>
	<view>

		<st-mc-framework :navTitle="ModuleTitle" @changeLevel="changeLevel"
			@AddModuleData_select='AddModuleData_select'>
			<template #workbench>

				<m-drag-button :style="{ opacity: BtnShow ? 1 : 0 }" :isDock="true" :existTabBar="true"
					class="m-drag-button-view" :initialBottom="60">
					<template #BtnContent>
						<u-icon name="search" color="#fff" size="25px" @click="search"></u-icon>
					</template>
				</m-drag-button>

			</template>
			<template #content>
				<view class="content_box f-dc">
					<view class="table table_top_th">
						<table>
							<tr>


								<th width='20%'>模具</th>
								<th width='23%'>设备</th>
								<th width='27%'>产品</th>
								<th width='10%'>下模人员</th>
								<th width='20%'>下模开始时间</th>

							</tr>
						</table>
					</view>
					<z-paging ref="paging" v-model="dataList" @query="queryList" :fixed="false" class="z_paging">
						<view class="table">
							<table class="table-full">
								<tbody>
									<tr style="border: 1px solid #ccc;" v-for="(item,index) in dataList" :key="index"
										@click="itemClick(item,index)">

										<td width='20%'>
											<view class="newlineDiv">
												<text>{{item.MoldNO}}</text>
											</view>

										</td>

										<td width='23%'>
											<view class="newlineDiv"><text>{{item.EquipmentCode}}</text></view>
										</td>
										<td width='27%'>
											<view class="newlineDiv"><text>{{item.ProductName}}</text></view>
										</td>
										<td width='10%'>
											<view class="newlineDiv"><text>{{item.EmpolorName}}</text></view>
										</td>
										<td width='20%'>
											<view class="newlineDiv"><text>{{item.StartTime}}</text></view>
										</td>
										<!-- 		<td width='7%' @click.stop style="padding: 5px;box-sizing: border-box;">
											<u-button text="上下模" color="#dbb56a"
												@click="addoperate(item,index)"></u-button>
										</td> -->

									</tr>
								</tbody>
							</table>
						</view>
					</z-paging>
				</view>
				<!-- 	<view class="add">
					<u-icon name="plus" color="#fff" size="30" @click="add"></u-icon>
				</view> -->
				<view class="search">
					<u-icon name="search" color="#fff" size="30" @click="search"></u-icon>
				</view>

				<uni-popup ref="popup" type="bottom" background-color="#fff" border-radius="10px 10px 0 0"
					@change="changePopup">
					<view class="popup_content">

						<u-cell-group :border='false'>
							<u-cell title="开始时间" :isLink="false" :value='FormData.FBDate'
								@click="addTime('开始')"></u-cell>
							<u-cell title="结束时间" :isLink="false" :value='FormData.FEDate'
								@click="addTime('结束')"></u-cell>

						</u-cell-group>
						<view class="bottomBtns">
							<button block @click="submit">
								查 &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp 询
							</button>
						</view>

					</view>
				</uni-popup>


				<u-datetime-picker :show="show" v-model="value1" mode="date" @cancel='show = false'
					@confirm='pickerConfirm'></u-datetime-picker>
			</template>

		</st-mc-framework>
		<m-loading :text="loadingName" v-model="showMLoading" :showClose="false"
			maskBackgroundColor="rgba(0,0,0,0.3)"></m-loading>
	</view>
</template>

<script>
	import {
		getTimeStamp,
		getFormatDateTime,
		getBefore7DateTime,
		formatDateTime,
		navigateMixin,
		baseAddModuleData_select,
		getchangeLevel
	} from '@/st_mes_zs/common/base.js';

	export default {
		mixins: [navigateMixin, baseAddModuleData_select],
		data() {
			return {
				confirmText: '确认',

				dataList: [],

				FormData: {
					PageIndex: 1,
					PageSize: 30,
					FBDate: '',
					FEDate: '',
					ChangeMoldType: 1,
				},
				APPFunID: 0,
				tabIndex: 0,
				showLeft: false,
				TimeName: '',
				show: false,
				value1: Number(new Date()),
				disabled: false,
				ModuleTitle: '', //标题名称
				showMLoading: false, //是否加载
				loadingName: '正在加载中……', //加载名称
				BtnShow: false, //按钮显示
			}

		},
		onShow() {
			var that = this
			uni.$on('refreshList', () => {
				this.getList(); // 调用目标方法
			});
		},
		onUnload() {
			uni.$off('refreshList');
		},

		onReady() {
			var that = this
			uni.hideLoading();
			that.showMLoading = true
			const {
				GuyueModule,
				UserInfo,
				appConfigInfo
			} = that.$store.state;
			const {
				MesBasicInfo
			} = GuyueModule;
			that.ModuleTitle = appConfigInfo.ActiveModule.ModuleName
		
			that.$nextTick(() => {
				setTimeout(() => {
					that.BtnShow = true;
				}, 500)
			})
		},
		onLoad(options) {
			var that = this
			that.$safeStatus({
				payload: '其他', // 要传递的数据
			});
			const {
				GuyueModule,
				UserInfo,
				appConfigInfo
			} = that.$store.state;
			const {
				MesBasicInfo
			} = GuyueModule;
			if (options.Dispatchitem) {
				const dispatchItem = JSON.parse(options.Dispatchitem);
				that.assignFormData(that.FormData, dispatchItem);
				return;
			}
			const formDefaults = {
				FBDate: getBefore7DateTime(),
				FEDate: getFormatDateTime(new Date()),
			};
			that.assignFormData(that.FormData, formDefaults);
		},

		methods: {
			// 创建表单赋值工具函数
			assignFormData(target, defaults = {}) {
				var that = this;
				Object.keys(defaults).forEach(key => {
					target[key] = defaults[key];
				});
				that.$forceUpdate();
			},

			getList() {
				this.contents = []; // 假设这是异步获取数据的操作
				this.$refs.paging.reload();
			},


			addTime(name) {
				this.TimeName = name
				if (this.TimeName == '开始') {
					this.value1 = Number(getTimeStamp(this.FormData.FBDate))
				} else {
					this.value1 = Number(getTimeStamp(this.FormData.FEDate))
				}
				this.show = true
			},

			pickerConfirm(e) {
				var time = getFormatDateTime(e.value)
				if (this.TimeName == '开始') {
					this.FormData.FBDate = time
				} else {
					this.FormData.FEDate = time
				}
				this.show = false
			},

			changePopup() {

			},
			search() {
				this.$refs.popup.open('bottom')

			},
			submit() {

				this.$refs.popup.close('bottom')
				this.contents = []; // 假设这是异步获取数据的操作
				this.$refs.paging.reload();
			},
			add() {
				let routes = getCurrentPages();


				var url = '/st_mes_zs/poweron/downMoldDetail'

				let obj = {
					path: 'manual',
					Name: '下模详情',
					APPFunID: '下模详情',
					length: routes.length + 1,
					url: url
				}

				this.GonavigateTo(obj, url)
			},
			queryList(pageNo) {
				let that = this;
				that.FormData.PageIndex = pageNo
				try {
					that.Request.request('getZSChangeMoldList', that.FormData, (ret) => {
						console.log(ret);
						if (ret.status == 200) {
							that.showMLoading = false
							ret.data.ds.map((item) => {
								item.StartTime = formatDateTime(item.StartTime)
							})
							that.$refs.paging.complete(ret.data.ds);
						} else {
							that.showMLoading = false
						}
					}, (err) => {
						that.showMLoading = false
					})
				} catch (e) {
					console.log(e)
					that.showMLoading = false
					this.$utils.hideLoading();
					this.$utils.msg('请求失败请重试')
				}
			},

			itemClick(item, index) {

				let routes = getCurrentPages();
				var url = `/st_mes_zs/poweron/downMoldDetail?ZSChangeMoldID=${item.ZSChangeMoldID}`


				let obj = {
					path: 'manual',
					Name: '下模详情',
					APPFunID: '下模详情',
					length: routes.length + 1,
					url: url
				}
				this.GonavigateTo(obj, url)
			},

			GonavigateTo(obj, url) {
				let that = this;
				var initData = JSON.parse(JSON.stringify(that.$store.state.GuyueModule.ModuleData_select));
				var parentData = initData[initData.length - 1]
				parentData.url = `/st_mes_zs/poweron/downMold?Dispatchitem=${JSON.stringify(that.FormData)}`;
				that.$modifyParentData(parentData);
				this.$safeNavigate({
					targetUrl: url, // 目标页面路径
					payload: obj, // 要传递的数据
				});
			},
			async AddModuleData_select(res) {
				try {
					const backDelta = await this.GetModuleData_select(res);
				} catch (error) {
					console.error('返回操作失败:');
				}
			},
			changeLevel(list, data, row) {
				getchangeLevel(data)

			},
		},


		onNavigationBarButtonTap(e) {
			if (this.showLeft) {
				this.$refs.showLeft.close()
			} else {
				this.$refs.showLeft.open()
			}
		},
		// app端拦截返回事件 ，仅app端生效
		onBackPress() {
			if (this.showRight || this.showLeft) {
				this.$refs.showLeft.close()
				this.$refs.showRight.close()
				return true
			}
		}
	}
</script>

<style lang="scss" >
	@import "../css/index.css";

	.popupShowList {
		width: 90vw;
		height: 60vh;

		background-color: #fff;

		font-size: 14px;
		border-radius: 4px !important;

		.popupText {

			white-space: normal;
			word-wrap: break-word;
			word-break: break-all;
		}

		.popupText text {
			font-size: 14px;
		}
	}

	.bottomBtns2 {
		padding-top: 5px;
		width: 100%;
		display: flex;

		button {
			display: inline-block;
			color: #fff;
			background-color: #51d0d0;
			width: 20%;
			font-size: 16px;
		}

	}
</style>